package it.stasbranger.myproject.service;

import it.stasbranger.myproject.domain.Requests;
import it.stasbranger.myproject.domain.SuppliersHasRequests;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/MyProject-security-context.xml",
		"file:./resources/MyProject-service-context.xml",
		"file:./resources/MyProject-dao-context.xml",
		"file:./resources/MyProject-web-context.xml" })
@Transactional
public class RequestsServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected RequestsService service;

	/**
	 * Instantiates a new RequestsServiceTest.
	 *
	 */
	public RequestsServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 * Return all Requests entity
	 * 
	 */
	@Test
	public void findAllRequestss() {
		// TODO: JUnit - Populate test inputs for operation: findAllRequestss 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Requests> response = null;
		response = service.findAllRequestss(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllRequestss
	}

	/**
	 * Operation Unit Test
	 * Delete an existing SuppliersHasRequests entity
	 * 
	 */
	@Test
	public void deleteRequestsSuppliersHasRequestses() {
		// TODO: JUnit - Populate test inputs for operation: deleteRequestsSuppliersHasRequestses 
		Integer requests_idrequests = 0;
		Integer related_suppliershasrequestses_suppliersIdsuppliers = 0;
		Integer related_suppliershasrequestses_requestsIdrequests = 0;
		Requests response = null;
		response = service.deleteRequestsSuppliersHasRequestses(requests_idrequests, related_suppliershasrequestses_suppliersIdsuppliers, related_suppliershasrequestses_requestsIdrequests);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteRequestsSuppliersHasRequestses
	}

	/**
	 * Operation Unit Test
	 * Save an existing SuppliersHasRequests entity
	 * 
	 */
	@Test
	public void saveRequestsSuppliersHasRequestses() {
		// TODO: JUnit - Populate test inputs for operation: saveRequestsSuppliersHasRequestses 
		Integer idrequests = 0;
		SuppliersHasRequests related_suppliershasrequestses = new it.stasbranger.myproject.domain.SuppliersHasRequests();
		Requests response = null;
		response = service.saveRequestsSuppliersHasRequestses(idrequests, related_suppliershasrequestses);
		// TODO: JUnit - Add assertions to test outputs of operation: saveRequestsSuppliersHasRequestses
	}

	/**
	 * Operation Unit Test
	 * Save an existing Requests entity
	 * 
	 */
	@Test
	public void saveRequests() {
		// TODO: JUnit - Populate test inputs for operation: saveRequests 
		Requests requests = new it.stasbranger.myproject.domain.Requests();
		service.saveRequests(requests);
	}

	/**
	 * Operation Unit Test
	 * Return a count of all Requests entity
	 * 
	 */
	@Test
	public void countRequestss() {
		Integer response = null;
		response = service.countRequestss();
		// TODO: JUnit - Add assertions to test outputs of operation: countRequestss
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findRequestsByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findRequestsByPrimaryKey 
		Integer idrequests_1 = 0;
		Requests response = null;
		response = service.findRequestsByPrimaryKey(idrequests_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findRequestsByPrimaryKey
	}

	/**
	 * Operation Unit Test
	 * Load an existing Requests entity
	 * 
	 */
	@Test
	public void loadRequestss() {
		Set<Requests> response = null;
		response = service.loadRequestss();
		// TODO: JUnit - Add assertions to test outputs of operation: loadRequestss
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Requests entity
	 * 
	 */
	@Test
	public void deleteRequests() {
		// TODO: JUnit - Populate test inputs for operation: deleteRequests 
		Requests requests_1 = new it.stasbranger.myproject.domain.Requests();
		service.deleteRequests(requests_1);
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
